#include "my_delay.h"
void tim7Init()
{
	TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStruct;
	RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM7, ENABLE);
	TIM_TimeBaseInitStruct.TIM_ClockDivision = TIM_CKD_DIV1;
	TIM_TimeBaseInitStruct.TIM_CounterMode = TIM_CounterMode_Up;
	TIM_TimeBaseInitStruct.TIM_Period = 1;
	TIM_TimeBaseInitStruct.TIM_Prescaler = 83;
	
	TIM_TimeBaseInit(TIM7, &TIM_TimeBaseInitStruct);
}

void myDelayUs(u16 nus)
{
	u32 cnt;
	cnt = nus;
	TIM_Cmd(TIM7, ENABLE);
	while(cnt--)
	{
		while(TIM_GetFlagStatus(TIM7, TIM_FLAG_Update) == RESET);
		TIM_ClearFlag(TIM7, TIM_FLAG_Update);
	}
	TIM_Cmd(TIM7, DISABLE);
}

void myDelayMs(u16 nms)
{
	u32 cnt;
	cnt = nms*1000;
	TIM_Cmd(TIM7, ENABLE);
	while(cnt--)
	{
		while(TIM_GetFlagStatus(TIM7, TIM_FLAG_Update) == RESET);
		TIM_ClearFlag(TIM7, TIM_FLAG_Update);
	}
	TIM_Cmd(TIM7, DISABLE);
}

